package models

import play.api.http.Status

case class TableData[T](
  code: Int = Status.OK,
  msg: String = "",
  count: Option[Int] = Option.empty,
  data: T)

object TableData {

  import io.circe._
  import io.circe.generic.extras._
  import io.circe.generic.extras.auto._

  private implicit val config: Configuration =
    Configuration.default.withDefaults

  implicit def tableDataJsonEncoder[T](
    implicit
    encoderT: Encoder[T]): Encoder[TableData[T]] = {
    exportEncoder.instance
  }

  def msg(message: String): TableData[Option[String]] =
    TableData(msg = message, data = Option.empty)
  def msg(message: String, code: Int): TableData[Option[String]] =
    TableData(code = code, msg = message, data = Option.empty)

}
